define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'monitor/mail/index',
                    add_url: 'monitor/mail/add',
                    edit_url: 'monitor/mail/edit',
                    del_url: 'monitor/mail/del',
                    multi_url: 'monitor/mail/multi',
                    table: 'mail_group',
                }
            });
            var parent_data = Config.parent_data;
            // console.log(Config.parent_data);
            var table = $("#table");
            var parent_data_arr = parent_data;
            var item = {0:'顶级'};
            parent_data_arr[0] = '顶级';
            delete parent_data_arr['-1'];
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'),operate:'LIKE',placeholder: __('模糊查询')},
                        {field: 'pid', title: __('Pid'),searchList:parent_data_arr,operate:'LIKE %...%'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('更新时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});